define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'user.user/index',
        // add_url: 'user.user/add',
        edit_url: 'user.user/edit',
        delete_url: 'user.user/delete',
        modify_url: 'user.user/modify',
        // order_url: 'product.order/index',
        // recharge_url: 'user.recharge/inc',
        // decmoney_url: 'user.recharge/dec',
    };

    var Controller = {

        index: function () {

            ea.table.render({
                init: init,
                toolbar: ['refresh'],
                sort: ['id', 'create_time'],
                cols: [[
                    {type: "checkbox"},
                    {
                        field: 'id', width: 80, title: 'ID', searchOp: '=', sort: true,/*templet: function (d){

                            return d.id+'<br/><span class="layui-badge layui-btn-danger layui-btn-normal">' +
                                '<div class="layuimini-qiuck-module" ><a layuimini-content-href="'+init.order_url+'?user_id='+d.id+'" title="查看订单">订单</a></div></span>';
                        }*/
                    },
                    {
                        field: 'client_type', width: 100, title: '用户类型',
                        selectList: {1: '微信', 2: '支付宝'}, templet: function (d) {
                            return d.client_name;
                        }
                    },
                    {field: 'nickname', minWidth: 80, title: '昵称'},
                    {
                        field: 'author', minWidth: 120, title: '权限', searchOp: '%*%' ,selectList: {'1':'消费者', '2':'商家', '3':'银行职员'},
                        templet: function (d) {
                            return d.author_list;
                        }
                    },
                    // {field: 'openid', minWidth: 160, title: 'openid',searchOp:'='},
                    // {field: 'openid', minWidth: 160, title: '微信',searchOp:'=',templet:function (d){
                    //         var nickname = d.nickname||'';
                    //         return '<span class="">昵称：'+d.nickname+'</span>' +
                    //             '<br/><span class="">'+d.openid+'</span>'
                    //     }
                    // },
                    {field: 'avatar_img', width: 80, title: '头像', search: false, templet: ea.table.image},
                    // {field: 'has_money1', minWidth: 50, title: '余额',searchOp:'number_range'},
                    {field: 'mobile', minWidth: 80, title: '手机', searchOp: '='},
                    {field: 'remark', minWidth: 80, title: '备注', edit: 'text'},
                    // {field: 'openid', minWidth: 80, title: '微信openID',searchOp:'='},
                    {field: 'area', minWidth: 80, title: '地区'},
                    {
                        field: 'status',
                        title: '状态',
                        width: 85,
                        search: 'select',
                        selectList: {0: '禁用', 1: '启用'},
                        templet: ea.table.switch
                    },
                    {
                        field: 'create_time', minWidth: 120, title: '时间', search: 'range', templet: function (d) {
                            var update_at = d.update_time || '未更新';
                            return '<div style="text-align: left"><span class="">注册：' + d.create_time + '</span>' +
                                '<br/><span class="">更新：' + update_at + '</span></div>'
                        }
                    },
                    // {field: 'update_time', minWidth: 80, title: '数据更新时间', search: 'range'},
                    {
                        width: 150,
                        title: '操作',
                        templet: ea.table.tool,
                        operate: [
                            // 'edit',
                            [/*{
                                text: '设置密码',
                                url: init.password_url,
                                method: 'open',
                                auth: 'password',
                                class: 'layui-btn layui-btn-normal layui-btn-xs',
                            },*/
                                {
                                    class: 'layui-btn  layui-btn-xs layui-btn-success',
                                    method: 'open',
                                    field: 'id',
                                    text: '编辑',
                                    title: '编辑',
                                    url: init.edit_url,
                                    auth: 'edit',
                                    extend: "",
                                },
                                // {
                                //     class: 'layui-btn  layui-btn-xs layui-btn-warning',
                                //     method: 'open',
                                //     field: 'id',
                                //     to_field: 'user_id',
                                //     icon: '',
                                //     text: '订单',
                                //     title: '查看订单',
                                //     url: init.order_url,
                                //     extend: "",
                                //     br: true
                                // },
                                // {
                                //     text: '充值',
                                //     url: init.recharge_url,
                                //     method: 'open',
                                //     auth: 'inc',
                                //     class: 'layui-btn layui-btn-normal layui-btn-xs',
                                // },
                                // {
                                //     text: '扣款',
                                //     url: init.decmoney_url,
                                //     method: 'open',
                                //     auth: 'dec',
                                //     class: 'layui-btn layui-btn-danger layui-btn-xs',
                                // }
                            ],
                            // 'delete'
                        ]
                    }
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});